package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/29
 * Time: 11:49
 * Description:
 */
public class DelOperation implements IOPeration{
    public void work(BookList bookList) {
        System.out.println("删除书籍");
        System.out.println("请输入图书的名字:");
        String name = scanner.nextLine();

        int index = 0;
        int size = bookList.getUsedSize();
        int i = 0;
        for (; i < size; i++) {
            Book bookCurrent = bookList.getBook(i);
            if(bookCurrent.getName().equals(name)) {
                index = i;
                break;
            }
        }
        //
        if(i == size) {
            System.out.println("没有你要删除的书籍！");
            return;
        }
        for (int j = index; j < size-1; j++) {
            //bookList[j] = bookList[j+1]
            Book book = bookList.getBook(j+1);
            bookList.setBooks(j,book);
        }
        bookList.setUsedSize(size-1);
        System.out.println("删除成功了！");
    }
}
